﻿using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace InfoPathHelpers.Cryptography
{
    /// <summary>
    /// Uses a symmetric key to encrypt elements and an asymmetric key to protect the symmetric key.
    /// </summary>
    public class AsymmetricKeyCryptography : SymmetricKeyCryptography
    {
        public AsymmetricKeyCryptography() : base(new RijndaelManaged()) { }

        public RSACryptoServiceProvider AsymmetricAlgorithm { get; set; }

        public string EncryptedKey 
        {
            get
            {
                return Convert.ToBase64String(AsymmetricAlgorithm.Encrypt(base.SymmetricAlgorithm.Key, true));
            }
        }

        public string EncryptedIV
        {
            get
            {
                return Convert.ToBase64String(AsymmetricAlgorithm.Encrypt(base.SymmetricAlgorithm.IV, true));
            }
        }
    }
}
